let backItemsApp=new Vue({
    el:"#backItemsApp",
    data:{
        items:[],
        pageInfo:{},
        cateId:""
    },
    methods:{
        loadBackItems:function (num) {
            if (num == null){
                num=1
            }
            axios({
                url:"/backItems/"+num,
                method:"get"
            }).then(function (response) {
                let itemsList=response.data.list
                backItemsApp.pageInfo=response.data
                for (let i = 0; i < itemsList.length; i++) {
                    if (itemsList[i].itemsStatus === 1){
                        itemsList[i].status="在售"
                    } else {
                        itemsList[i].status="下架"
                    }
                }
                backItemsApp.items=itemsList
            })
        },
        loadItemsCate:function () {
            axios({
                url: "/categories",
                method:"get"
            }).then(function (response) {
                backItemsApp.categories=response.data
            })
        },
        deleteItem:function (itemsId,index,items) {
            axios({
                url:"/backItems/delete/"+itemsId,
                method:"get"
            }).then(function (response) {
                if (response.data === "ok"){
                    items.splice(index,1)
                }else {
                    alert(response)
                }
            })
        }

    },
    created:function () {
        this.loadBackItems()
    }
})


